﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.CustomerManagement
{
    public partial class Golf_UserDataModify : Golf.WebUI.App_code.ValidateLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {
            Golf.BLL.Golf_UserData bll = new Golf.BLL.Golf_UserData();
            Golf.Model.Golf_UserData model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();
            this.txtUserId.Text = model.UserId.ToString();
            this.txtFristName.Text = model.FristName;
            this.txtLastName.Text = model.LastName;
            this.txtsex.Text = model.sex.ToString();
            this.txtBirthday.Text = model.Birthday.ToString();
            this.txtMobile.Text = model.Mobile;
            this.txtTel.Text = model.Tel;
            this.txtFax.Text = model.Fax;
            this.txtQQ.Text = model.QQ;
            this.txtMsn.Text = model.Msn;
            this.txtAddress.Text = model.Address;
            this.txtPostCode.Text = model.PostCode;
            this.txtProvince.Text = model.Province;
            this.txtCity.Text = model.City;
            this.txtBorough.Text = model.Borough;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "用户id格式错误！\\n";
            }
            if (this.txtFristName.Text.Trim().Length == 0)
            {
                strErr += "姓不能为空！\\n";
            }
            if (this.txtLastName.Text.Trim().Length == 0)
            {
                strErr += "名不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtsex.Text))
            {
                strErr += "性别 1男 0女格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtBirthday.Text))
            {
                strErr += "身日格式错误！\\n";
            }
            if (this.txtMobile.Text.Trim().Length == 0)
            {
                strErr += "手机不能为空！\\n";
            }
            if (this.txtTel.Text.Trim().Length == 0)
            {
                strErr += "电话不能为空！\\n";
            }
            if (this.txtFax.Text.Trim().Length == 0)
            {
                strErr += "传真不能为空！\\n";
            }
            if (this.txtQQ.Text.Trim().Length == 0)
            {
                strErr += "QQ不能为空！\\n";
            }
            if (this.txtMsn.Text.Trim().Length == 0)
            {
                strErr += "msn不能为空！\\n";
            }
            if (this.txtAddress.Text.Trim().Length == 0)
            {
                strErr += "地址不能为空！\\n";
            }
            if (this.txtPostCode.Text.Trim().Length == 0)
            {
                strErr += "邮编不能为空！\\n";
            }
            if (this.txtProvince.Text.Trim().Length == 0)
            {
                strErr += "省不能为空！\\n";
            }
            if (this.txtCity.Text.Trim().Length == 0)
            {
                strErr += "市不能为空！\\n";
            }
            if (this.txtBorough.Text.Trim().Length == 0)
            {
                strErr += "区不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int Id = int.Parse(this.lblId.Text);
            int UserId = int.Parse(this.txtUserId.Text);
            string FristName = this.txtFristName.Text;
            string LastName = this.txtLastName.Text;
            int sex = int.Parse(this.txtsex.Text);
            DateTime Birthday = DateTime.Parse(this.txtBirthday.Text);
            string Mobile = this.txtMobile.Text;
            string Tel = this.txtTel.Text;
            string Fax = this.txtFax.Text;
            string QQ = this.txtQQ.Text;
            string Msn = this.txtMsn.Text;
            string Address = this.txtAddress.Text;
            string PostCode = this.txtPostCode.Text;
            string Province = this.txtProvince.Text;
            string City = this.txtCity.Text;
            string Borough = this.txtBorough.Text;


            Golf.Model.Golf_UserData model = new Golf.Model.Golf_UserData();
            model.Id = Id;
            model.UserId = UserId;
            model.FristName = FristName;
            model.LastName = LastName;
            model.sex = sex;
            model.Birthday = Birthday;
            model.Mobile = Mobile;
            model.Tel = Tel;
            model.Fax = Fax;
            model.QQ = QQ;
            model.Msn = Msn;
            model.Address = Address;
            model.PostCode = PostCode;
            model.Province = Province;
            model.City = City;
            model.Borough = Borough;

            Golf.BLL.Golf_UserData bll = new Golf.BLL.Golf_UserData();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }

}